<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 * Init Model
 *
 */


class Admin_location_model extends CI_Model {

	function __construct(){
		parent::__construct();


	}

	public function state_list(){
		$sql = "Select * from state";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $result;
		}else{
			return NULL;
		}
	}

	public function get_state($state_id = NULL){
		$sql = "Select * from state where id=$state_id";
		$query = $this->db->query($sql);
		$row = $query->row();
		if($row){
			return $row;
		}else{
			return NULL;
		}
	}

	function city_list($state_id)
	{
		$sql = "Select * from city where stateid=$state_id";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $result;
		}else{
			return NULL;
		}
	}

	public function get_city($city_id = NULL){
		$sql = "Select * from city where id=$city_id";
		$query = $this->db->query($sql);
		$row = $query->row();
		if($row){
			return $row;
		}else{
			return NULL;
		}
	}

	function get_state_name($state=NULL) {
		if ($state) {
			$code = trim($state);
			$sql = "Select * from state where id='$code'";
			$query = $this->db->query($sql);
			$row = $query->row();
			if ($query->num_rows == 1)
				return $row->statename;
		}
	}

	public function state_delete($id=NULL) {

		$this->db->where('id', $id);
		$this->db->delete('state');

		$this->db->where('stateid', $id);
		$this->db->delete('city');


	}

	public function city_delete($id=NULL) {

		$this->db->where('id', $id);
		$this->db->delete('city');

	}
	
	//--Get All Country Name-- rahul4u1994@gmail.com--//
	public function get_states($limit=0)
	
	{
		$sql = "select * from state ORDER BY (statename) asc limit $limit";


		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $result;
		}
		else{
			return null;
		}
	}
	
	//--Get All Country Name-- rahul4u1994@gmail.com--//
	public function get_statess($limit=0)
	{
		$sql = "select * from state ORDER BY (statename) asc limit $limit";
	
	
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $result;
		}
		else{
			return null;
		}
	}
	public function get_cityy($state_id=NULL,$num=NULL, $offset=NULL) {
	
		$sql = "Select * from city where stateid=$state_id";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $result;
		}else{
			return NULL;
		}
		//var_dump($result);
		//die();
	}
	function get_cities_by_state($stateID = null){
		//echo $stateID;die;
		$this->db->select('*');
	
		if($stateID != NULL){
			$this->db->where('stateid', $stateID);
		}
		$query = $this->db->get('city');
	
	
		$cities = array();
	
		if($query->result()){
			foreach ($query->result() as $city) {
				$cities[$city->id] = $city->cityname;
			}
			return $cities;
	
		}else{
			return FALSE;
		}
	
	
	}
}
//** end of Code //